package cn.e4j.core.util;

import ch.qos.logback.core.PropertyDefinerBase;
import org.springframework.stereotype.Component;

/**
 * author by ganjia
 * date: 2019-12-06
 */
// 通过实现logback的PropertyDefinerBase方法,动态定义logback配置中的变量
@Component
public class DefineLogBack extends PropertyDefinerBase {
    /**
     * 根据当前服务器名动态配置日志编码格式
     * @return
     */
    private String getCharset() {
        String charset = null;
        String os = System.getProperty("os.name");//获取当前服务器名
        if(os.toLowerCase().startsWith("win")){
            charset = "GBK";
        }else if(os.toLowerCase().startsWith("mac")){
            charset = "UTF-8";
        } else if(os.toLowerCase().startsWith("linux")){
            charset = "UTF-8";
        }else {
            charset = "UTF-8";
        }
        return charset;

    }
    @Override
    public String getPropertyValue() {
        return getCharset();
    }
}
